// system verilog file has NO module-endmodule structure
// system verilog DPI (!) has program main and endprogram
// mix and match C and verilog
// but the structures within are verilog's
// below is the 'main' program
program main;
   initial
   begin
       string str1,str2,str3;
       str1 = "TEST BENCH";
       str2 = "TEST BENCH";
       str3 = "test bench";
       if(str1 == str2)
           $display(" Str1 and str2 are equal");
       else
           $display(" Str1 and str2 are not equal");
       if(str1 == str3)
           $display(" Str1 and str3 are equal");
       else
           $display(" Str1 and str3 are not equal");
       
   end
endprogram


// C function which contains the definition for 'match' function
function match(string s1,s2);
    int l1,l2;
    l1 = s1.len();
    l2 = s2.len();
    match = 0 ;
    if( l2 > l1 )
        return 0;
    for(int i = 0;i < l1 - l2 + 1; i ++)
        if( s1.substr(i,i+l2 -1) == s2)
            return 1;
endfunction

// here is another program-endprogram structure
// this uses the match function defined above
// compiling it in questasim results in 'main' and 'main1' in the work library
// either of the program could be run by 'vsim main' or 'vsim main1'

program main1;
string str1,str2;
int i;

   initial
   begin
       str1 = "this is first string";
       str2 = "this";
       if(match(str1,str2))
           $display(" str2 : %s : found in :%s:",str2,str1);
   
       str1 = "this is first string";
       str2 = "first";
       if(match(str1,str2))
           $display(" str2 : %s : found in :%s:",str2,str1);
   
       str1 = "this is first string";
       str2 = "string";
       if(match(str1,str2))
           $display(" str2 : %s : found in :%s:",str2,str1);
   
       str1 = "this is first string";
       str2 = "this is ";
       if(match(str1,str2))
           $display(" str2 : %s : found in :%s:",str2,str1);
   
       str1 = "this is first string";
       str2 = "first string";
       if(match(str1,str2))
           $display(" str2 : %s : found in :%s:",str2,str1);
   
       str1 = "this is first string";
       str2 = "first string ";// one space at end
       if(match(str1,str2))
           $display(" str2 : %s : found in :%s:",str2,str1);
       
   end

endprogram

